from django.http import HttpResponse

from TestModel.models import Test

def testdb(request):
    # # 相当于创建了数据
    # test1 = Test(name='runoob')
    # # 保存数据
    # test1.save()
    # return HttpResponse("<p>数据添加成功</p>")
    response1 = ""

    # 相当于select *
    listTest = Test.objects.all()

    response2 = Test.objects.filter(id=1)
    response3 = Test.objects.get(id=1)

    # 限制返回的数据 相当于limit
    Test.objects.order_by('name')[0:2]

    Test.objects.order_by("id")

    Test.objects.filter(name='runoob').order_by("id")

    for var in listTest:
        response1 += var.name + " "
    response = response1
    return HttpResponse("<p>" + response + "</p>")

def update(request):
    # test = Test.objects.get(id=1)
    # test.name = 'Google'
    # test.save()

    Test.objects.filter(id=1).update(name='runoob')

    return HttpResponse("<p>修改成功</p>")